#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
const int N = 2e5 + 10;

using PII = pair<int, int>;
using LL = long long;

int n;
LL q[N];
LL d[N];


void init(int x){
    
    for(int i = 1; i <= x; i ++) d[i] = 0;
    for(int i = 0; i <= x; i ++) q[i] = 0;
}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);

    int T;
    scanf("%d", &T);
    while(T--){
        scanf("%d", &n);
        init(n);
        for(int i = 1; i <= n; i ++){
            scanf("%lld", &q[i]);
            d[i] += q[i], d[i + 1] -= q[i];
        }
   

        LL res = 0;
        for(int i = 2; i <= n; i ++){
            if(d[i] > 0){
                res += d[i];
            }else if(d[i] < 0){
                d[1] += d[i];
                res += abs(d[i]);
            }
        }
        res += abs(d[1]);
        printf("%lld\n", res);
        
    }
    return 0;
}